import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/ps/planOrder/list',
  save='/ps/planOrder/add',
  edit='/ps/planOrder/edit',
  deleteOne = '/ps/planOrder/delete',
  deleteBatch = '/ps/planOrder/deleteBatch',
  importExcel = '/ps/planOrder/importExcel',
  exportXls = '/ps/planOrder/exportXls',
  psPlanOrderVersionList = '/ps/planOrder/queryPsPlanOrderVersionByMainId',
  psPlanOrderItemList = '/ps/planOrder/queryPsPlanOrderItemByMainId',
  psPlanOrderResultList = '/ps/planOrder/queryPsPlanOrderResultByMainId',
  psPlanOrderOrganizationList = '/ps/planOrder/queryPsPlanOrderOrganizationByMainId',
  psPlanOrderLogList = '/ps/planOrder/queryPsPlanOrderLogByMainId',
  psPlanOrderDeductionList = '/ps/planOrder/queryPsPlanOrderDeductionByMainId',
  mrpCalculate = '/ps/planOrder/calculate',
  psPlanOrderItemDelete = '/ps/planOrder/psPlanOrderItemDelete',
  mpsQueryByMainId = '/psProductionPlanMps/queryPsProductionPlanMpsItemByMainId',
  queryMpsItemByMainIds = '/psProductionPlanMps/queryItemByMainIds',
  queryArrangementItemByMainIds = '/ps/psProductionArrangementPlans/queryItemByMainIds',
  supplyAndDemandList = 'ps/psPlanningScheduling/scheduling/getSupplyDemandList'
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 查询子表数据
 * @param params
 */
export const psPlanOrderVersionList = Api.psPlanOrderVersionList;
/**
 * 查询子表数据
 * @param params
 */
export const psPlanOrderItemList = Api.psPlanOrderItemList;
/**
 * 删除单个
 * @param params
 */
export const deleteItem = (id,handleSuccess) => {
  return defHttp.get({url: Api.psPlanOrderItemDelete, params: {id}}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 查询子表数据
 * @param params
 */
export const psPlanOrderResultList = Api.psPlanOrderResultList;

/**
 * 查询子表数据
 * @param params
 */
export const psPlanOrderOrganizationList = Api.psPlanOrderOrganizationList;
/**
 * 查询子表数据  日志
 * @param params
 */
export const psPlanOrderLogList = Api.psPlanOrderLogList;
/**
 * 查询子表数据  供需明细
 * @param params
 */
export const supplyAndDemandList = Api.supplyAndDemandList;
/**
 * 查询子表数据
 * @param params
 */
export const psPlanOrderDeductionList = Api.psPlanOrderDeductionList;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});

// 获取mps详情
export const getMpsQueryByMainId = (params) =>
  defHttp.get({url: Api.mpsQueryByMainId, params});

// 根据主生产计划id集合批量查询明细
export const getMpsItemByMainIds = (params) =>
  defHttp.get({url: Api.queryMpsItemByMainIds, params});
// 根据总装排查计划id集合批量查询明细
export const getArrangementItemByMainIds = (params) =>
  defHttp.get({url: Api.queryArrangementItemByMainIds, params});

/**
 * 删除单个
 * @param params
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}

// mrp运算
export const postMrpCalculate = (params) => {
  return defHttp.post({url: Api.mrpCalculate, params},{joinParamsToUrl:true});
}